import { onMounted } from 'vue';
import { useLocale } from '@/locale/locale';
import { isWechat } from '@/utils/platform';

type UseTitleCallback = () => void;

const noop = () => {};

export function useTitle(key?: string, callback: UseTitleCallback = noop) {
  const { t } = useLocale();

  onMounted(() => {
    if (!isWechat()) {
      uni.setNavigationBarTitle({
        title: key ? t(key) : 'Apartment 11'
      });

      callback();
    }
  });
}
